<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :span="12">
            <a-form-item label="钢号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['steelSpecification', validatorRules.steelSpecification]" placeholder="请输入钢号" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['standard']" placeholder="请输入规格" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="材质" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['qualit']" placeholder="请输入材质" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="图号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['figureNumber']" placeholder="请输入图号" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="版次" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['version']" placeholder="请输入版次" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="位置" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['location']" placeholder="请输入位置" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="单重量(kg)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['singleWeight']" placeholder="请输入单个重量(kg)" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="总重(kg)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['totalWeight']" placeholder="请输入总重(kg)" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="单长度(m)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['singleLenght']" placeholder="请输入单个长度(m)" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="总长(m)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['totalLenght']" placeholder="请输入总长(m)" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['count', validatorRules.count]" placeholder="请输入数量" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="面积" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['area']" placeholder="请输入面积" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['remark']" placeholder="请输入备注" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="工艺路线" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-popup
                v-decorator="['flowName']"
                :trigger-change="true"
                org-fields="id,flow_name"
                dest-fields="flowId,flowName"
                code="tj_flow"
                @callback="popupCallback" disabled/>
              <a-input v-decorator="['flowId']" hidden disabled></a-input>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "FrameModal",
    components: {
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
          steelSpecification: {
            rules: [
              { required: true, message: '请输入钢号!'},
              { validator: (rule, value, callback) => validateDuplicateValue('frame', 'steel_specification', value, this.model.id, callback)},
            ]
          },
          count: {
            rules: [
              { required: true, message: '请输入数量!'},
            ]
          },
        },
        url: {
          add: "/engine/engineering/addFrame",
          edit: "/engine/engineering/editFrame",
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'steelSpecification','standard','qualit','figureNumber','version','location','singleWeight','totalWeight','singleLenght','totalLenght','count','area','remark','flowId','flowName','engineeringId','createBy','createTime','updateBy','updateTime','sysOrgCode'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.close()
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'steelSpecification','standard','qualit','figureNumber','version','location','singleWeight','totalWeight','singleLenght','totalLenght','count','area','remark','flowId','flowName','engineeringId','createBy','createTime','updateBy','updateTime','sysOrgCode'))
      },


    }
  }
</script>
